<template>
  <div class="app-container container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="事件编码" prop="sjCode">
        <el-input
          v-model="queryParams.sjCode"
          placeholder="请输入事件编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微震震源位置" prop="zyLocation">
        <el-input
          v-model="queryParams.zyLocation"
          placeholder="请输入微震震源位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生时间">
        <el-date-picker
          v-model="daterangeOccurTime"
          size="small"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          popper-class="custom-class"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          circle  
          @click="handleQuery"
          ></el-button
        >
        <el-button icon="el-icon-refresh" size="mini" circle type="warning" @click="resetQuery"
          ></el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="quakeRealDataList"
      :row-class-name="tableRowClassNameT"
    >
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="事件编码"
        align="center"
        prop="sjCode"
        width="180"
      />
      <el-table-column
        label="记录微震事件的通道号"
        align="center"
        prop="recordChannelNumber"
        width="180"
      />
      <el-table-column
        label="震源坐标X"
        align="center"
        prop="zyX"
        width="180"
      />
      <el-table-column
        label="震源坐标Y"
        align="center"
        prop="zyY"
        width="180"
      />
      <el-table-column
        label="震源坐标Z"
        align="center"
        prop="zyZ"
        width="180"
      />
      <el-table-column
        label="震源能量"
        align="center"
        prop="zyEnergy"
        width="180"
      />
      <el-table-column
        label="震源震级"
        align="center"
        prop="zyLevel"
        width="180"
      />
      <el-table-column
        label="微震震源位置"
        align="center"
        prop="zyLocation"
        width="180"
      />
      <el-table-column
        label="最大振幅"
        align="center"
        prop="zfMax"
        width="180"
      />
      <el-table-column
        label="平均振幅"
        align="center"
        prop="zfAvg"
        width="180"
      />
      <el-table-column
        label="微震事件波形主频"
        align="center"
        prop="wzEventZp"
        width="180"
      />
      <el-table-column
        label="发生时间"
        align="center"
        prop="occurTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.occurTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="事件分析结论"
        align="center"
        prop="eventAnalysisConclusion"
        width="180"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      class="page"
    />
  </div>
</template>

<script>
import { listQuakeRealData } from "@/api/realData/quakeRealData";

export default {
  name: "QuakeRealData",
  props: {
    parenttime: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微震监测实时信息表格数据
      quakeRealDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 发生时间时间范围
      daterangeOccurTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mineCode: null,

        mineName: null,

        cdCode: null,

        sjCode: null,

        recordChannelNumber: null,

        zyX: null,

        zyY: null,

        zyZ: null,

        zyEnergy: null,

        zyLevel: null,

        zyLocation: null,

        zfMax: null,

        zfAvg: null,

        wzEventZp: null,

        occurTime: null,

        eventAnalysisConclusion: null
      },
      // 表单参数
      form: {},
      stime: "",
      etime: ""
    };
  },
  created() {
    if (this.parenttime == "0") {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
      this.stime = this.newDate(start)
      this.etime = this.newDate(end)
      this.daterangeOccurTime.push( this.stime);
      this.daterangeOccurTime.push(this.etime);
    } else {
      this.daterangeOccurTime = [];
    }
    this.getList();
  },
  methods: {
    newDate(time) {
      var date = new Date(time);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      var s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s;
    },
    tableRowClassNameT({ rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "evencolort";
      } else {
        return "oddcolort";
      }
    },
    /** 查询微震监测实时信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOccurTime && "" != this.daterangeOccurTime) {
        this.queryParams.params["beginOccurTime"] = this.daterangeOccurTime[0];
        this.queryParams.params["endOccurTime"] = this.daterangeOccurTime[1];
      }
      listQuakeRealData(this.queryParams).then(response => {
        this.quakeRealDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        mineCode: null,

        mineName: null,

        cdCode: null,

        sjCode: null,

        recordChannelNumber: null,

        zyX: null,

        zyY: null,

        zyZ: null,

        zyEnergy: null,

        zyLevel: null,

        zyLocation: null,

        zfMax: null,

        zfAvg: null,

        wzEventZp: null,

        occurTime: null,

        eventAnalysisConclusion: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOccurTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
